package com.bw.liuyushan.zhuangao4_mvptest1.MVP.Model;

import com.bw.liuyushan.mvp_lib.Model.BaseModel;
import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIBanner;
import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIFood;
import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIMain;
import com.bw.liuyushan.zhuangao4_mvptest1.BaseUrl.APIUser;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.BannerBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.JsonBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.UserBean;
import com.bw.liuyushan.zhuangao4_mvptest1.Entity.ViedoBean;
import com.bw.liuyushan.zhuangao4_mvptest1.MVP.Contrack.ICTest;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.BannerManager;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.FoodrManager;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.RxJavaManager;
import com.bw.liuyushan.zhuangao4_mvptest1.Utils.UserManager;

import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;

/**
 * ZhuanGao4_MVPTest1
 * file name is : BaseModelTest
 * created by Ender on 2021/8/11 14:37.
 * author : Liuyushan
 * Describe:M层实现类 负责使用网络框架请求数据 传递到P层
 */
public class BaseModelTest extends BaseModel implements ICTest.C_ModelTest {
    /***
     * 请求快手视频
     * @param url
     * @param observer
     */
    @Override
    public void askDate(String url, Observer<ViedoBean> observer) {
        RxJavaManager.getInstance().getRetrofit().create(APIMain.class)
                .TestUrl(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /**
     * 请求轮播图
     * @param observer
     */
    @Override
    public void askBanner(Observer<BannerBean> observer) {
        BannerManager.getInstance().getRetrofit().create(APIBanner.class)
                .BannerUrl()
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);

    }

    /***
     * 请求大虾串
     * @param url
     * @param observer
     */
    @Override
    public void askFood(String url,Observer<JsonBean> observer) {
        FoodrManager.getInstance().getRetrofit().create(APIFood.class)
                .FoodUrl(url)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);

    }

    /**
     * 用户登录
     * @param name
     * @param pwd
     * @param observer
     */
    @Override
    public void askLogin(String name, String pwd, Observer<UserBean> observer) {
        UserManager.getInstance().getLogin().create(APIUser.class)
                .login(name, pwd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    /***
     * 用户注册
     * @param name
     * @param pwd
     * @param observer
     */
    @Override
    public void askReg(String name, String pwd, Observer<UserBean> observer) {
        UserManager.getInstance().getLogin().create(APIUser.class)
                .reg(name, pwd)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }
}
